package com.example.administrator.szb.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * Created by D N on 2017/11/27.
 */

public class VersinoUtil {
    /**
     * 返回当前程序版本名
     * @param name_or_code 1,代表版本名称，0代表版本号
     */
    public static Object getAppVersionName(Context context,int name_or_code) {
        String versionName = "";
        int versioncode = 0;
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            versioncode = pi.versionCode;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        if (name_or_code == 1){
            return versionName;
        }else{
            return versioncode;
        }

    }
}
